// TagEngine.cpp: implementation of the CTagEngine class.
//
//////////////////////////////////////////////////////////////////////

#include "TagEngine.h"

#include "MMediaTag.h"
#include "MediaTagFactory.h"		//For class CMediaTagFactory

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTagEngine::CTagEngine()
{

}

CTagEngine::~CTagEngine()
{

}

void CTagEngine::Prepare()
{
}

TInt CTagEngine::ChangeTag(const CDesCArray& aFileList, const CDesCArray& aTagNames, const CDesCArray& aTagValues)
{
	// Pre check
	if (aTagNames.Count() != aTagValues.Count())
	{
		return TAGENG_COUNTNOTEQUAL;
	}

	if (aTagNames.Count() == 0 || aTagValues.Count() == 0)
	{
		return TAGENG_NOVALUETOCHAGNE;
	}

	for (int i=0; i<aFileList.Count(); i++)
	{
		MMediaTag* pTag = TMediaTagFactory::GetMediaTagL(aFileList[i]);

		if (pTag)
		{
			int nErr = pTag->ChangeTagL(iFsSession, aTagNames, aTagValues);
			nErr;
		}
		
	}

	return TAGENG_PROCESSUCCESS;
}

TInt CTagEngine::Process()
{
	return 0;
}

void CTagEngine::Test(TFileName& aFile)
{
	User::LeaveIfError(iFsSession.Connect());

	MMediaTag* pTag = TMediaTagFactory::GetMediaTagL(aFile);
	CleanupStack::PushL(pTag);

	pTag->ConstructL(iFsSession, aFile);


	CDesCArrayFlat* name = new(ELeave) CDesCArrayFlat(6);
	CDesCArrayFlat* value = new(ELeave) CDesCArrayFlat(6);
//
//	CleanupStack::PushL(name);
//	CleanupStack::PushL(value);
//	
	name->AppendL(_L("Artist"));
	value->AppendL(_L("Ma811"));

	name->AppendL(_L("Year"));
	value->AppendL(_L("1990"));

	name->AppendL(_L("Comment"));
	value->AppendL(_L("No comments"));
//
	pTag->ChangeTagL(iFsSession, *name, *value);
//	
	iFsSession.Close();
//
	delete name;
	delete value;

	delete pTag;
	
	CleanupStack::Pop();
}